<%@ Control Language="C#" AutoEventWireup="true" CodeFile="usrPhoneNo.ascx.cs" Inherits="controls_PhoneNo" %>
<span class="indicator">+65&nbsp;</span><span class="indicator"><asp:TextBox ID="txtPhoneNo"
    runat="server" MaxLength="8" ToolTip="Enter 8 digits phone number."></asp:TextBox></span>
<span class="indicator">
    <%--Require Phone Number--%>
    <asp:RequiredFieldValidator validationErrorCssClass="validationError" ID="rfvPhoneNo"
        runat="server" ControlToValidate="txtPhoneNo" ErrorMessage="" Text="" Display="Dynamic"></asp:RequiredFieldValidator>
</span><span class="indicator">
    <%--Phone number is not valid.--%>
    <asp:CustomValidator validationErrorCssClass="validationError" ID="csvPhoneNo" runat="server"
        ClientValidationFunction="CheckPhoneNoClientValidate" ControlToValidate="txtPhoneNo"
        Display="Dynamic" Text="" ErrorMessage="" OnServerValidate="CheckPhoneNoServerValidation"></asp:CustomValidator>
    <%--Phone number must be 8 digits number value.--%>
    <asp:RegularExpressionValidator validationErrorCssClass="validationError" ID="revPhoneNo"
        runat="server" ValidationExpression="[0-9]{8}" ControlToValidate="txtPhoneNo"
        ErrorMessage="" Text="" Display="Dynamic"></asp:RegularExpressionValidator>
</span>

<script type="text/javascript">
<!--

   function PhoneNoLengthClientValidate(source, arguments)
   {
        if (arguments.Value.length != 0 && arguments.Value.length < 8 ){
            arguments.IsValid = false;
        } else {
            arguments.IsValid = true;
        }
   }
   
   function CheckPhoneNoClientValidate(source, arguments)
   {
        var cval = parseInt(arguments.Value)
        if (isNaN(cval)){
            arguments.IsValid = false;
        } else {
            var cstrVal = "" + cval + "";
            if(cstrVal.length < 8)
            {
                arguments.IsValid = false;
            }
            else if(cstrVal.charAt(0) != "6" && 
                    cstrVal.charAt(0) != "8" &&
                    cstrVal.charAt(0) != "9") 
            {
                arguments.IsValid = false;
            }
            else
            {
                arguments.IsValid = true;
            }
        }
   }
    //-->
</script>

